package dao;

import model.Report_in;
import model.Report_out;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class Dao_money extends Dao{
    //获取所有出库财务信息
    public static List select_outMoneyAll()
    {
        List list = new ArrayList();
        String sql = "select * from report_money_out group by o_time";

        ResultSet re = executeQuery(sql);
        try {
            while (re.next())
            {
                Report_out report_out = new Report_out();

                report_out.setO_no(re.getString("o_no"));
                report_out.setC_name(re.getString("c_name"));
                report_out.setCs_name(re.getString("cs_name"));
                report_out.setO_price(re.getString("o_price"));
                report_out.setO_time(re.getString("o_time"));
                report_out.setO_realPrice(re.getString("o_realprice"));

                list.add(report_out);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return list;
    }

    //获取所有入库财务信息
    public static List select_inMoneyAll() {
        List list = new ArrayList();
        String sql = "select distinct * from report_money_out  group by i_time";

        ResultSet re = executeQuery(sql);
        try {
            while (re.next()) {
                Report_in report_in = new Report_in();

                report_in.setI_no((re.getString("i_no")));
                report_in.setC_name(re.getString("c_name"));
                report_in.setCs_name(re.getString("cs_name"));
                report_in.setI_price(re.getString("i_price"));
                report_in.setI_time(re.getString("i_time"));
                report_in.setI_realsPrice(re.getString("i_realprice"));

                list.add(report_in);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    //通过日期获得出库财务信息
    public static List select_outMoney(String outTime)
    {
        List list = new ArrayList();
        String sql = "select * from report_money_out where o_time = '" + outTime + "'";

        ResultSet re = executeQuery(sql);
        try {
            while (re.next())
            {
                Report_out report_out = new Report_out();

                report_out.setO_no(re.getString("o_no"));
                report_out.setC_name(re.getString("c_name"));
                report_out.setCs_name(re.getString("cs_name"));
                report_out.setO_price(re.getString("o_price"));
                report_out.setO_time(re.getString("o_time"));
                report_out.setO_realPrice(re.getString("o_realprice"));

                list.add(report_out);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    //通过日期获得入库财务信息
    public static List select_inMoney(String inTime)
    {
        List list = new ArrayList();
        String sql = "select * from report_money_in where i_time = '" + inTime + "'";

        ResultSet re = executeQuery(sql);
        try {
            while (re.next())
            {
                Report_in report_in = new Report_in();

                report_in.setI_no((re.getString("i_no")));
                report_in.setC_name(re.getString("c_name"));
                report_in.setCs_name(re.getString("cs_name"));
                report_in.setI_price(re.getString("i_price"));
                report_in.setI_time(re.getString("i_time"));
                report_in.setI_realsPrice(re.getString("i_realprice"));


                list.add(report_in);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return list;
    }

    //获得出库时间
    public static Vector<String> getOutTime()
    {
        List list = Dao_reportOut.select_outAll();
        Vector<String> WareID = new Vector<>();

        for(int i = 0; i < list.size(); i++)
        {
            Report_out report_out = (Report_out) list.get(i);
            WareID.add(report_out.getO_time());
        }

        return WareID;
    }


    //获得入库时间
    public static Vector<String> getInTime()
    {
        List list = Dao_reportIn.select_inAll();
        Vector<String> WareID = new Vector<>();

        for(int i = 0; i < list.size(); i++)
        {
            Report_in report_in = (Report_in) list.get(i);
            WareID.add(report_in.getI_time());
        }

        return WareID;
    }
}
